package com.lfy.commons.strategy;

import com.lfy.commons.config.interceptor.AuthHandlerInterceptor;
import com.lfy.commons.utils.IpUtil;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
/**
 * 限流策略
 *
 * @author <a href="https://www.lvfeiy.top">吕飞扬</a>
 * @date 2023/10/16 15:12
 */

public enum LimitStrategyEnum {
    Ip{
        @Override
        public String toDo() {
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = attributes.getRequest();
            return IpUtil.getIpAddress(request);
        }
    },
    Id{
        @Override
        public String toDo() {
            return AuthHandlerInterceptor.authLocal.get().getId().toString();
        }
    }
    ;

    public abstract String toDo();
}
